package main

import "fmt"

func init() {
	print("初始化函数")
}

func main() {
	slice := []int{1, 2, 3, 4, 5, 6, 7}
	odds := filter(slice, isOdd)
	evens := filter(slice, isEven)

	fmt.Println("odds>", odds)

	fmt.Println("evens>", evens)
}

func sayHi() {
	print("Hi ... How are you . . . ")
}

// 声明一个函数类型
type testInt func(int) bool

func isOdd(integer int) bool {
	if integer%2 == 0 {
		return false
	}
	return true
}

func isEven(integer int) bool {
	return !isOdd(integer)
}

func filter(slince []int, f testInt) []int {

	var result []int
	for _, value := range slince {
		if f(value) {
			result = append(result, value)
		}
	}
	return result
}
